package com.shfl.task.exception;

import com.shfl.task.common.ResCodeMessage;
import org.quartz.JobExecutionException;

public class ApiTaskException extends JobExecutionException {

    String resCode;
    String resDesc;

    public ApiTaskException(String resCode) {
        super(ResCodeMessage.getMessageDesc(resCode));
        this.resCode = resCode;
        resDesc = super.getMessage();
    }

    public ApiTaskException(String code, String resDesc) {
        super(resDesc);
        this.resCode = code;
        this.resDesc = resDesc;
    }

    static ApiException newException(String resCode) throws ApiException {
        return new ApiException(resCode);
    }

    static ApiException newException(String resCode, String resDesc) throws ApiException {
        return new ApiException(resCode, resDesc);
    }

    static ApiException newExceptionWithArgs(String resCode, Object... args) {
        String message = ResCodeMessage.getMessageDesc(resCode);
        String rseDesc = String.format(message, args);
        return new ApiException(resCode, rseDesc);
    }


    public String getResCode() {
        return resCode;
    }

    public void setResCode(String resCode) {
        this.resCode = resCode;
    }

    public String getResDesc() {
        return resDesc;
    }

    public void setResDesc(String resDesc) {
        this.resDesc = resDesc;
    }
}
